package com.spzx.channel.service.impl;

import com.spzx.channel.service.CategoryService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryNestedVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Haoran Sun
 * @since 2024/07/24
 */

@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private RemoteCategoryService remoteCategoryService;


    @Override
    public List<CategoryNestedVo> tree() {
        R<List<CategoryNestedVo>> result = remoteCategoryService.tree(SecurityConstants.INNER);
        if(R.isSuccess(result)) return result.getData();
        log.error("获取分类树失败{}", result.getMsg());
        throw new ServiceException(result.getMsg());
    }
}
